/**
 * 类型断言
 */

function getValueLength(msg: any) {
    //msg默认为any类型,无法推断出他有split
    const res = (msg as any).split("")
    //msg是any类型,无法确认length
    return (<string>msg).length
}

const value2 = getValueLength(123)


let someValue: any = "this is a string";

//告诉编辑器，someValue在使用的时候，一定是string类型。不要默认推断
let strLength: number = (<string>someValue).length;
let strLength2: number = (someValue as string).length;


interface IStudent {
    id:number,
    name:string
}
const student:IStudent = {
    id:1,
    name:"小五"
}
function getValueByKey(obj:IStudent,key:string){
    return obj["name"]
}
const result = getValueByKey(student,"address")
